package com.hssy.wululuaplan.controller;


import com.hssy.wululuaplan.common.Result;
import com.hssy.wululuaplan.entity.PaymentRecord;
import com.hssy.wululuaplan.form.PaymentInsertUpdateForm;
import com.hssy.wululuaplan.form.PaymentQueryForm;
import com.hssy.wululuaplan.form.StudentForm;
import com.hssy.wululuaplan.service.PaymentRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 缴费管理 前端控制器
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2024-02-28
 */
@Api(tags = "缴费管理")
@RestController
@RequestMapping("/wululuaplan/payment-record")
public class PaymentRecordController {

    @Resource
    private PaymentRecordService paymentRecordService;

    @ApiOperation("条件查询全部缴费记录")
    @GetMapping("/queryFindAll")
    public Result<List<PaymentRecord>> queryFindAll(PaymentQueryForm form) {
        List<PaymentRecord> list = paymentRecordService.queryFindAll(form);
        return Result.success(list);
    }

    @ApiOperation("根据id查询缴费记录")
    @GetMapping("/findById")
    public Result<PaymentRecord> findById(@RequestParam(value = "id") Integer id){
        PaymentRecord record = paymentRecordService.getById(id);
        return Result.success(record);
    }

    @ApiOperation("查询指定学生的缴费记录")
    @GetMapping("/findByStudentId")
    public Result<List<PaymentRecord>> findByStudentId(@RequestParam(value = "studentId", required = false) Integer studentId,
                                                       @RequestParam(value = "studentName", required = false)String studentName,
                                                       @RequestParam(value = "expenseItem",required = false) String expenseItem){
        List<PaymentRecord> record = paymentRecordService.findByStudentId(studentId,studentName,expenseItem);
        return Result.success(record);
    }


    @ApiOperation("新增缴费记录")
    @PostMapping("/create")
    public Result<String> create(@RequestBody @Valid PaymentInsertUpdateForm form) {
        paymentRecordService.create(form);
        return Result.success();
    }

    @ApiOperation("修改缴费记录")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody PaymentInsertUpdateForm form) {
        paymentRecordService.edit(form);
        return Result.success();
    }

    @ApiOperation("删除缴费记录")
    @PostMapping("/delete")
    public Result<String> delete(Integer id) {
        paymentRecordService.delete(id);
        return Result.success();
    }


    @ApiOperation("查询欠费的人")
    @GetMapping("debtPeople")
    public Result<List<String>> debtPeople() {
        List<String> list = paymentRecordService.debtPeople();
        return Result.success(list);
    }
}

